#include "head_s.h"


int ls(const user_t* status, const portocol_t* portocol, int net_fd)
{
    // if(strcmp(buf, "ls") == 0){
    char buf1[1024] = {0};
    recv(net_fd, buf1, sizeof(buf1), 0);

    char buf2[1024] = {0};
    // size_t len2 = strlen(status->user_name);
    // char buf3[1024] = {0};
    // size_t len3 = strlen(status->base_path);
    // strcat(buf1, buf2);
    // strcat(buf1, buf3);
    sprintf(buf2, "%s/%s/%s", status->base_path, status->user_name, buf1);

    DIR* dirp = opendir(buf2);
    struct dirent* pdir;
    char buff[1024];
    // int num = 0;
    while((pdir = readdir(dirp)) != NULL){
        // printf("%s\n", pdir->d_name);
        // num++;
        // snprintf(buff, sizeof(buff), "%s\n", pdir->d_name);
        strncat(buff, "   ", sizeof(buff));
        strncat(buff, pdir->d_name, sizeof(buff));
    }   
    int send_t = send(net_fd, buff, sizeof(buff), 0);
    if(send_t == -1){
        perror("send failed!\n");
        exit(1);
    }
    // }
    // int send_num = send(net_fd, &num, sizeof(int), 0);

    // send(net_fd, buff, strlen(buff), 0);

    closedir(dirp);

    return 0;
}

